package com.realgodo.site.web.user.communication;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.opensymphony.xwork2.Action;
import com.realgodo.site.entity.application.communication.Commentary;
import com.realgodo.site.entity.application.communication.Reply;
import com.realgodo.site.service.communication.ReplyManager;

@Scope("prototype")
@Result(name = Action.SUCCESS, type = "redirect", location = "${base}/user/communication/reply!list?communicationId=${id}")
public class ReplyController extends IndexController {
	/** */
	private static final long serialVersionUID = -2153208894578271399L;
	
	@Autowired
	protected ReplyManager replyManager;
	/**评论实体*/
	private Reply reply;
	
	private List<Reply> replyList;
	
	/**发表评论*/
	public String execute() throws Exception {
		return save();
	}

	/**保存评论*/
	public String save(){
		if(reply.getCommentary()==null){
			Commentary commentary=new Commentary();
			commentary.setId(id);
			reply.setCommentary(commentary);
		}
		reply.setPublisher(super.getSpace());
		reply=replyManager.saveReply(reply);
		id=reply.getCommentary().getId();
		return moddle==null||"".equals(moddle)?SUCCESS:moddle;
	}
	
	/**回复列表（AJAX刷新）*/
	public String list(){
		replyList=replyManager.findReplyList(super.getParamMap());
		return "list"+moddle;
	}
	
	//------------------get/set---------//
	public Reply getReply() {
		return reply;
	}

	public void setReply(Reply reply) {
		this.reply = reply;
	}

	public List<Reply> getReplyList() {
		return replyList;
	}
	
	
}
